<template>
    <div class="welcome">
        <h2 class="container">欢迎来到MochiMap</h2>
    </div>
</template>

<script setup>
import { onMounted } from 'vue';
import { useRouter } from 'vue-router';

// 通过useRouter()访问全局路由
const router = useRouter();

// onMounted()  在welcome组件挂载后执行
onMounted(() => {
    const token = localStorage.getItem('token');
    console.log(token);

    setTimeout(() => {
        if (token) {
            router.push('/main');
        } else {
            router.push('/login');
            console.log('没有token，跳转到登录页');
        }
    }, 3000);
});
</script>

<style lang="css" scoped>
* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

.welcome {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-image: url('../assets/img/photo.png');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    padding: 20px;
}

.container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 360px;
    height: 180px;
    background: rgba(255, 246, 246, 0.85);
    backdrop-filter: blur(8px);
    border-radius: 24px;
    font-size: 32px;
    font-family: 'Noto Sans JP', sans-serif;
    font-weight: bold;
    color: #791919;
    text-shadow: 2px 2px 4px rgba(107, 33, 97, 0.3);
    box-shadow: 
        0 0 15px 5px rgba(255, 246, 246, 0.6),
        0 10px 25px rgba(121, 25, 25, 0.1);
    padding: 20px;
    text-align: center;
    animation: fadeIn 1s ease-out;
    transform-style: preserve-3d;
    transition: all 0.5s ease;
}

.container:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 
        0 0 20px 8px rgba(255, 246, 246, 0.7),
        0 15px 35px rgba(121, 25, 25, 0.15);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 480px) {
    .container {
        height: 150px;
        font-size: 28px;
        border-radius: 20px;
    }
}
</style>